package com.metaedu.framework;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author Chenin
 * @version Jun 2, 2015
 */
@Controller
public class RootAction {
	public static class POJO {
		@NotNull
		@Length(min = 10, max = 20)
		public String code;

		@NotEmpty
		public String name;
	}

	@RequestMapping("X.do")
	public @ResponseBody Object X(@Valid @RequestBody POJO pojo) {
		return pojo;
	}

	@RequestMapping("T.php")
	public String R(HttpServletRequest request, HttpServletResponse response) {
		return "index";
	}

	@RequestMapping("index.php")
	public ModelAndView R(ModelAndView mav) {
		mav.setViewName("index");
		return mav;
	}
}
